package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.VipPageQueryDTO;
import com.sky.entity.Vip;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface VipMapper {

    /**
     * 根据id查询会员信息
     * @param id
     * @return
     */
    @Select("select * from vip where id = #{id}")
    Vip getById(Long id);

    /**
     * 根据用户id查询会员信息
     * @param userId
     * @return
     */
    @Select("select * from vip where user_id = #{userId}")
    Vip getByUserId(Long userId);

    /**
     * 插入会员数据
     * @param vip
     */
    @Insert("insert into vip (user_id, level, create_time, start_time, end_time, update_time) " +
            "values " +
            "(#{userId}, #{level}, #{createTime}, #{startTime}, #{endTime}, #{updateTime})")
    @AutoFill(value = OperationType.INSERT)
    void insert(Vip vip);

    /**
     * 删除会员信息
     * @param id
     */
    @Update("delete from vip where id = #{id}")
    void delete(Long id);

    /**
     * 更新会员信息
     * @param vip
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Vip vip);

    /**
     * 分页查询
     * @param vipPageQueryDTO
     * @return
     */
    Page<Vip> pageQuery(VipPageQueryDTO vipPageQueryDTO);
} 